using System;
using System.Collections.Generic;
using System.Text;

namespace Gl.SettingsManager
{
	public class Int64ValidatorAttribute : NumericValidatorBaseAttribute
	{
		private long _minValue = 0;
		private long _maxValue = 0;
		private long _defaultValue = 0;

		public long DefaultValue
		{
			get { return _defaultValue; }
			set { _defaultValue = value; }
		}

		public Int64ValidatorAttribute(long minValue, long maxValue)
		{
			_maxValue = maxValue;
			_minValue = minValue;
		}

		public override void Validate(ref object value)
		{
			long valueShort = Convert.ToInt64(value);
			bool valid = false;

			if (CheckMaximum && (_maxValue < valueShort))
				valid = false;

			if (CheckMinimum && (_minValue > valueShort))
				valid = false;

			if (!valid)
			{
				if (ThrowExceptionOnNotValid)
					throw new SettingsException(Exceptions.NotValidValue,
						GetType().FullName);
				else
					value = _defaultValue;
			}
		}
	}

}
